<?php

namespace App\Console\Commands;

use App\Jobs\SendEmailRedis;
use Bschmitt\Amqp\Facades\Amqp;
use Illuminate\Cache\RedisLock;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class EmailProducer extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'email:produce';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Email Producer...';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     * @throws \Exception
     */
    public function handle()
    {

        RedisLock::class;
        for ($i=0;$i<5;$i++){
            $random = microtime(true);
            $this->info(date('Y-m-d H:i:s') .' '. $random);
            Amqp::publish('HelloWorld', (string)$random);
            Amqp::publish('route01', (string)$random);
            SendEmailRedis::dispatch($random)
                ->onQueue('email');

        }
        return Command::SUCCESS;
    }




}
